const app = getApp()
const api = app.globalData.api

Page({

  /**
   * 页面的初始数据
   */
  data: {
    active:0,
    menu:[],
    staff:[],
    num:0,
  },

  onTabChange(event){
    this.setData({
      active:event.detail.index
    })
    this.requstData();
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    let recordDate = !api.isBlank(options.recordDate)?options.recordDate:'';
    let hallId = !api.isBlank(options.hallId)?options.hallId:'';
    let mealType = !api.isBlank(options.mealType)?options.mealType:'';
    that.setData({
      hallId,
      mealType,
      recordDate,
    });
    this.requstData();
  },
  requstData(){
    let that = this;
    if(this.data.active==0){
      api.curlPost('?cla=canteenApp&fun=statisticsDetail',{recordDate:this.data.recordDate,hallId:this.data.hallId,mealType:this.data.mealType,classify:'报餐'}).then((res)=>{
        that.setData({ 
          menu:res.data.list,
          staff:res.data.people,
          num:res.data.peopleNum,
        })
      })
    }else if(this.data.active==1){
      api.curlPost('?cla=canteenApp&fun=statisticsDetail',{recordDate:this.data.recordDate,hallId:this.data.hallId,mealType:this.data.mealType,classify:'取餐'}).then((res)=>{
        that.setData({ 
          menu:res.data.list,
          staff:res.data.people,
          num:res.data.peopleNum,
        })
      })
    }else if(this.data.active==2){
      api.curlPost('?cla=canteenApp&fun=statisticsDetail',{recordDate:this.data.recordDate,hallId:this.data.hallId,mealType:this.data.mealType,classify:'未取餐'}).then((res)=>{
        that.setData({ 
          menu:res.data.list,
          staff:res.data.people,
          num:res.data.peopleNum,
        })
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})